/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.baatar.opt.genetic.test.xx;

import org.baatar.opt.genetic.GeneticIterationListener;
import org.baatar.opt.genetic.GeneticOptimizer;
import org.baatar.opt.genetic.comparator.MinimizationComparator;
import org.baatar.opt.genetic.crossover.UniformCrossover;
import org.baatar.opt.genetic.selection.BinaryTournamentSelection;

/**
 *
 * @author Ba
 */
public class mainXX {
    public static void main(String args[]) throws Exception {
        GeneticOptimizer<Character> go = new GeneticOptimizer<Character>();

        ChromosomeFactoryMinXXSquare chromosomeFactory = new ChromosomeFactoryMinXXSquare();

        go.setMaxNumOfIterations(500);
        go.setMaxNumOfIterationsWOProgress(200);
        go.setPopulationSize(100);
        go.setNumOfChildren(20);
        go.setNumOfEliteChromosomes(4);
        go.setMutationRate(0.01);
        go.setGreedRate(0.03);
        go.setAllowDublicateChromosomes(false);

        go.setComparator(new MinimizationComparator<Character>());
        go.setChromosomeFactory(chromosomeFactory);
        go.setSelector(new BinaryTournamentSelection<Character>());
        go.setMutator(new MutatorMinXXSquare());
        go.setCrossoverOperator(new UniformCrossover<Character>());

        go.setGeneticIterationListener(new GeneticIterationListener<Character>() {
            @Override
            public void onProgress(GeneticOptimizer<Character> go, int iteration, String info) {
                System.out.println(iteration + " - " + info);
            }

            @Override
            public void onIterate(int iteration, int numOfIterationsPassedWOProgress, int maxNumOfIterations) {
            }
        });

        try {
            if (go.initialize())
                go.start();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}
